//
//  HeaderView.m
//  Travels
//
//  Created by yanghuiyan on 16/3/16.
//  Copyright © 2016年 yanghuiyan. All rights reserved.
//

#import "HeaderView.h"
#import "UIImageView+WebCache.h"
#import "UserModel.h"
#define Width self.bounds.size.width
#define Height self.bounds.size.height
@implementation HeaderView

- (void)dealloc {
    
    [_backImageView release];
    [_userImageView release];
    [_nameLabel release];
    [super dealloc];
    
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
      
        self.backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -50, self.bounds.size.width, 250)];
        [self addSubview:self.backImageView];
        
        self.userImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * Width / 416, self.bounds.size.height - 80 * Width / 736 + 50 *Width / 736, 45 * Width / 416, 45 * Width / 416)];
//        self.userImageView.backgroundColor = [UIColor cyanColor];
//        self.userImageView.layer.cornerRadius = (45 * Width / 416) / 2;
//        self.userImageView.layer.masksToBounds = YES;
//        self.userImageView.layer.borderWidth = 2;
//        self.userImageView.layer.borderColor = [UIColor whiteColor].CGColor;
        [self.backImageView addSubview:self.userImageView];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(25 * Width / 416, self.userImageView.frame.origin.y +  25 * Height / 736, Width - (self.userImageView.frame.origin.x + self.userImageView.frame.size.width + 20 * Width / 416) , 35 * Width / 736)];
        self.nameLabel.textColor = [UIColor whiteColor];
        self.nameLabel.font = [UIFont systemFontOfSize:18];
        [self.backImageView addSubview:self.nameLabel];
        
    }
    return self;
}

- (void)setDetailModel:(DetailModel *)detailModel {
    if (_detailModel != detailModel) {
        [_detailModel release];
        _detailModel = [detailModel retain];
    }
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:detailModel.front_cover_photo_url]];
//    [_userImageView sd_setImageWithURL:[NSURL URLWithString:detailModel.userNew.image]];
    _nameLabel.text = detailModel.name;
    NSLog(@"%@", detailModel.name);

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
